home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
msqc25t1
/
textscrn.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-26
|
9KB
|
237 lines
/* textscrn.c: Stretching text screen operations for QC 2.0 */
/* Library source
This program must be compiled in large model.
*/
#include <graph.h>
#include <dos.h>
#include <string.h>
#include <stdarg.h>
#include <malloc.h>
#include <stdio.h>
#include "biosarea.h"
#include "mk_fp.h"
#include "textscrn.h"
#if !defined TRUE
#define FALSE 0
#define TRUE !FALSE
#endif
typedef struct scrnimage {
unsigned char dispmem [4000];
struct scrnimage far *prev;
struct rccoord textpos;
short fgcolor, bgcolor;
} SCRNIMAGE;
BIOSDATA far *bios = MK_FP (0x40, 0); /* ROM BIOS data area */
struct videoconfig video; /* video configuration */
int init_done = FALSE; /* if initialized */
SCRNIMAGE far *scrnstack = NULL; /* screen image stack pointer */
/*-------------------------------------------------------------------------*/
/* LOCAL ROUTINE */
/*-------------------------------------------------------------------------*/
void near initialize (void) /* initalize for these fcns */
{
_getvideoconfig (&video); /* get video info */
init_done = TRUE; /* set switch */
}
/*-------------------------------------------------------------------------*/
/* CONTROL FUNCTIONS */
/*-------------------------------------------------------------------------*/
void far _outtextf (char *ps, ...) /* Formatted output */
{ /* Pass arg as for printf() */
char fline [80];
va_list ap;
va_start (ap, ps);
vsprintf (fline, ps, ap); /* format string */
va_end (ap);
_outtext (fline); /* write to video memory */
} /*-------------------------------*/
void far _outch (char ch) /* Single char output */
{
char str [2];
str [0] = ch; /* make a short string */
str [1] = '\0';
_outtext (str); /* and output it */
} /*-------------------------------*/
void far _cleareol (void) /* clear to end of line from */
{ /* current cursor position */
register c;
char blank [81];
struct rccoord text;
if (!init_done) initialize(); /* be sure we're set up */
for (c = 0; c < 80; c++) blank [c] = ' '; /* clear blank */
text = _gettextposition(); /* where are we? */
c = video.numtextcols - text.col; /* how far to right edge? */
blank [c+1] = '\0'; /* make blank that long */
_outtext (blank); /* write spaces */
_settextposition (text.row, text.col); /* restore cursor */
} /*-------------------------------*/
void far _textbox (int top, int left,
int bott, int rite, int style)
/* Draw box in text mode */
/* Style arguments: */
/* 0 = no box */
/* 1 = single-scored */
/* 2 = double-scored */
{
register r, c;
char horiz [81];
static bord [][6] = { /* border characters */
{ 196, 179, 218, 191, 217, 192 },
{ 205, 186, 201, 187, 188, 200 }
};
if (style == 0 ) return; /* no action, else... */
/* Initialize */
for (c = 0; c < 81; c++) horiz[c] = '\0'; /* horiz string */
--style; /* index to border set */
/* Make sure coords are in proper oder */
if (left > rite) c = left, left = rite, rite = c;
if (top > bott) c = top, top = bott, bott = c;
/* Draw top */
for (c=1; c<rite-left; c++)
horiz[c] = bord [style][0]; /* horiz char */
horiz[c] = bord [style][3]; /* top right corner */
horiz[0] = bord [style][2]; /* top left corner */
_settextposition (top,left);
_outtext (horiz); /* draw it */
/* Draw bottom */
horiz[c] = bord [style][4]; /* bottom right corner */
horiz[0] = bord [style][5]; /* bottom left corner */
_settextposition (bott,left);
_outtext (horiz); /* draw it */
/* Draw sides */
for (r = top+1; r < bott; r++) {
_settextposition (r, left); /* left side */
_outch (bord [style][1]); /* vertical char */
_settextposition (r, rite); /* right side */
_outch (bord [style][1]); /* vertical char */
}
} /*-------------------------------*/
void far _savescrn (int page ) /* save screen image */
/* pushes image onto a stack */
{
SCRNIMAGE far *new;
unsigned char far *vidmem;
short oldpage;
oldpage = _setactivepage (page); /* remember where we are */
new = _fmalloc (sizeof (SCRNIMAGE)); /* get space */
new->prev = scrnstack; /* point to previous image */
scrnstack = new; /* update stack pointer */
new->textpos = _gettextposition(); /* save cursor position */
new->fgcolor = _gettextcolor(); /* save current colors */
new->bgcolor = _getbkcolor();
vidmem = (bios->videoMode == 7) /* video memory addr */
? MK_FP (0xB000, (page * 0x1000))
: MK_FP (0xB800, (page * 0x1000));
movedata (FP_SEG (vidmem), FP_OFF (vidmem), /* save image */
FP_SEG (new), FP_OFF (new), 4000);
_setactivepage (oldpage); /* return to active page */
} /*-------------------------------*/
void far _restscrn (int page ) /* restore screen image */
/* pops image off a stack */
{
unsigned char far *vidmem;
SCRNIMAGE far *top;
short oldpage;
if (scrnstack) { /* proceed if stack not empty */
_settextwindow (1, 1, 25, 80);
oldpage = _setactivepage (page); /* remember where we are */
top = scrnstack; /* top of stack */
vidmem = (bios->videoMode == 7) /* video memory addr */
? MK_FP (0xB000, (page * 0x1000))
: MK_FP (0xB800, (page * 0x1000));
movedata (FP_SEG (top), FP_OFF (top), /* save image */
FP_SEG (vidmem), FP_OFF (vidmem), 4000);
_settextcolor (top->fgcolor); /* restore colors */
_setbkcolor ((long)(top->bgcolor));
_settextposition /* restore cursor position */
(top->textpos.row, top->textpos.col);
if(oldpage != page)
_setactivepage (oldpage); /* return to active page */
scrnstack = top->prev; /* update stack pointer */
_ffree (top); /* free space */
}
} /*-------------------------------*/
void far _setbordwindow (int top, int left, /* bordered window */
int bott, int rite,
int style, int fgcolor, int bgcolor)
{
int c;
/* Make sure coords are in proper oder */
if (left > rite) c = left, left = rite, rite = c;
if (top > bott) c = top, top = bott, bott = c;
/* Construct border window */
_settextwindow (1, 1, 25, 80); /* use full screen */
_settextcolor (fgcolor); /* set colors */
_setbkcolor ((long)(bgcolor));
_textbox (top-1, left-1, bott+1, rite+1, style); /* border */
_settextwindow (top, left, bott, rite); /* open window */
_clearscreen (_GWINDOW); /* clear window */
} /*-------------------------------*/
/*-------------------------------------------------------------------------*/
/* INQUIRY FUNCTIONS */
/*-------------------------------------------------------------------------*/
int far maxcol (void) /* max column on display */
{
if (!init_done) initialize();
return video.numtextcols;
} /*-------------------------------*/
int far maxrow (void) /* max row on display */
{
if (!init_done) initialize();
return video.numtextrows;
} /*-------------------------------*/
int far maxpage (void) /* highest avail video page */
{
if (!init_done) initialize();
return video.numvideopages;
} /*-------------------------------*/
int far wherex (void) /* cursor col in active page */
{
struct rccoord text;
text = _gettextposition();
return text.col;
} /*-------------------------------*/
int far wherey (void) /* cursor row in active page */
{
struct rccoord text;
text = _gettextposition();
return text.row;
} /*-------------------------------*/